public class Solution {
    public static String multiply(String num1, String num2) {
        if (num1.equals("0") || num2.equals("0")) {
            return "0";
        }
        int len1 = num1.length();
        int len2 = num2.length();
        int len = len1 + len2;
        int[] ret = new int[len];
        StringBuilder num11 = new StringBuilder();
        StringBuilder num22 = new StringBuilder();

        num11.append(num1);
        num1 = num11.reverse().toString();

        num22.append(num2);
        num2 = num22.reverse().toString();

        char[] arr1 = num1.toCharArray();
        char[] arr2 = num2.toCharArray();

        //先进行无进位相加
        for (int j = 0; j < len2; j++) {//arr2
            for (int i = 0; i < len1; i++) {//arr1
                ret[i + j] += Integer.parseInt(Character.toString(arr1[i])) * Integer.parseInt(Character.toString(arr2[j]));
            }
        }

        //处理进位
        for (int i = 0; i < len - 1; i++) {
            ret[i + 1] += ret[i] / 10;
            ret[i] %= 10;
        }

        //逆序结果
        StringBuilder temp = new StringBuilder();
        for (int i = 0; i < len; i++) {
            temp.append(Integer.toString(ret[i]).charAt(0));
        }

        //处理首位0
        String ret2 =  temp.reverse().toString();
        if (ret2.charAt(0) == '0') {
            ret2 = ret2.substring(1, ret2.length());
        }

        return ret2;
    }

    public static void main(String[] args) {
        System.out.println(multiply("123", "456"));
    }
}
